package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 生成订单表
     *
     * @param orders
     * @return
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);

    /**
     * 查询用户所有订单
     *
     * @param orders
     * @return
     */
    Page<Orders> queryByHistoryOrders(Orders orders);

    /**
     * 根据id查询订单的信息
     *
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders queryById(Long id);

    /**
     * 根据id删除订单
     *
     * @param orders
     * @return
     */

    void cancel(Orders orders);

    /**
     * 商家订单查询
     *
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> queryByPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 更新全部数据
     *
     * @param orders
     * @return
     */
    void updateData(Orders orders);

    /**
     * 查询超时订单
     *
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> queryTimeout(Integer status, LocalDateTime time);

    /**
     *
     *
     * @param
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> queryForAutoSetComplete(Integer status,LocalDateTime time);

    /**
     * 统计营业额
     *
     * @param map
     * @return
     */
    BigDecimal queryForAmount(Map map);

    /**
     * 统计订单数
     *
     * @param map
     * @return
     */
    Integer orderStatistics(Map map);

    /**
     * 查询销量排名
     *
     * @param map
     * @return
     */
    List<GoodsSalesDTO> top10(Map map);
}
